$(() => {
    const token = GetQueryString("token");
    let user_id = $('.user_id').attr('data-user_id');
    let company_id = $('.company_id').attr('data-company_id');
    let company_confirm = $('.company_confirm').attr('data-company_confirm');
    let company_level = $('.company_level').attr('data-company_level');

    if (token) {
        // 个人
        $.ajax({
            type: "post",
            url: url,
            data: {
                'method': 'User|user_center',
                'token': token
            },
            dataType: 'json',
            success: function(res) {
                if (res.status == 1) {
                    let data = res.data;
                    // 个人id
                    let user_id = data.user_id;
                    $('.user_id').attr('data-user_id', user_id);
                    // 企业id
                    let company_id = data.company_id;
                    $('.company_id').attr('data-company_id', company_id);
                    // 是否认证企业
                    let company_confirm = data.company_confirm;
                    $('.company_confirm').attr('data-company_confirm', company_confirm);
                    // 企业等级
                    let company_level = data.company_level;
                    $('.company_level').attr('data-company_level', company_level);

                    $("#nick_name").html(data.nick_name);
                    let is_company = data.level_logo;
                    if (is_company == "") {
                        $("#is_company").html("个人用户").css("margin-top", ".2rem");
                    } else {
                        $("#is_company .userLevel").attr("src", data.level_logo);
                    }
                    $(".userImg img").attr("src", data.img_head == '' ? './img/user.jpg' : data.img_head);
                } else if (res.status == 2) {
                    location.href = "fox://logout";
                } else {
                    alert(res.message);
                }
            }
        })
    }

    // 设置
    $('.settings').on('click', function() {
        location.href = "view/setting.html?token=" + token;
    })
    // 个人详情
    $('.userImg').on('click', function() {
        let company_confirm = $('.company_confirm').attr('data-company_confirm');
        if (company_confirm == 1) {
            if (token) {
                let company_id = $('.company_id').attr('data-company_id');
                location.href = "view/shop_details_company.html?company_id=" + company_id + '&token=' + token;
            } else {
                location.href = "fox://logout";
            }
        } else {
            if (token) {
                let user_id = $('.user_id').attr('data-user_id');
                location.href = "view/shop_details_personal.html?user_id=" + user_id + '&token=' + token;
            } else {
                location.href = "fox://logout";
            }
        }
    })

    // 我的店铺/企业
    if (company_confirm == 0) {
        $('.myShop p').html('我要开店');
        $('.myShop').on('click', function() {
            if (token) {
                location.href = 'view/my_shop.html?token=' + token;
            } else {
                location.href = "fox://logout";
            }
        })
    } else {
        $('.myShop').on('click', function() {
            let company_id = $('.company_id').attr('data-company_id');
            if (company_level >= 1) {
                if (token) {
                    location.href = "view/shop_details_company.html?company_id=" + company_id + "&token=" + token;
                } else {
                    location.href = "fox://logout";
                }
            } else {
                if (token) {
                    location.href = "view/shop_details.html?company_id=" + company_id + "&token=" + token;
                } else {
                    location.href = "fox://logout";
                }
            }
        })
    }



    //我要发布、
    $('.iWantSend').on('click', function() {
        if (token) {
            // location.href = "view/ring_add.html?token=" + token;
            location.href = 'fox://publish';
        } else {
            location.href = "fox://logout";
        }
    })
    // 个人信息
    $('.personalMsg').on('click', function() {
        if (token) {
            location.href = "view/personal_details.html?token=" + token;
        } else {
            location.href = "fox://logout";
        }
    })
    // 我的建材圈
    $('.single_forum').on('click', function() {
        let user_id = $('.user_id').attr('data-user_id');
        if (token) {
            location.href = 'view/building_circle.html?userid=' + user_id + '&token=' + token;
        } else {
            location.href = "fox://logout";
        }
    })
    $('.weiChat').on('click', function() {
        if (token) {
            location.href = "fox://session";
        } else {
            location.href = "fox://logout";
        }
    })
    // 收藏企业
    $('.collect_company').on('click', function() {
        if (token) {
            location.href = "view/collect_company.html?token=" + token;
        } else {
            location.href = "fox://logout";
        }
    })
    // 收藏商品
    $('.collect_goods').on('click', function() {
        if (token) {
            location.href = "view/collect_product.html?token=" + token;
        } else {
            location.href = "fox://logout";
        }
    })
})